package org.example.common.utils;

/**
 * @Description ThreadLocal 工具类，用于保存当前线程的用户信息
 * @Author xiaotian
 * @Date 2025-04-04
 */
public class ThreadLocalUtil {

    private static final ThreadLocal<String> USER_ID_THREAD_LOCAL = new ThreadLocal<>();
    private static final ThreadLocal<String> PATH_API_THREAD_LOCAL = new ThreadLocal<>();

    public static void setUserId(String userid) {
        USER_ID_THREAD_LOCAL.set(userid);
    }

    public static String getUserId() {
        return USER_ID_THREAD_LOCAL.get();
    }

    public static void setPathApi(String pathApi) {
        PATH_API_THREAD_LOCAL.set(pathApi);
    }

    public static String getPathApi() {
        return PATH_API_THREAD_LOCAL.get();
    }

    public static void clear() {
        USER_ID_THREAD_LOCAL.remove();
        PATH_API_THREAD_LOCAL.remove();
    }
}